package com.proxy.main;

import java.sql.SQLException;
import java.util.List;

import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;

import com.proxy.dao.Proxy;
import com.proxy.dao.ProxyDao;
import com.proxy.thread.ThreadPool;
import com.proxy.util.DataSourceUtil;

/**
 * Proxy checking follow control.
 *
 */
public class ProxyCheckingController {
	
	private ProxyDao proxyDao = new ProxyDao();
	
	/**
	 * Get proxy data from proxyDao object, start threadPool object.
	 * @throws SQLException
	 */
	public void startCheck() throws SQLException
	{
		ThreadPool threadPool = new ThreadPool();
		List<Proxy> myProxyList = proxyDao.getProxyList();
		
		// Create an HttpClient with the ThreadSafeClientConnManager.
        // This connection manager must be used if more than one thread will
        // be using the HttpClient.
        PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
        connectionManager.setMaxTotal(50);
        connectionManager.setDefaultMaxPerRoute(5);
        
        HttpClient httpclient = new DefaultHttpClient(connectionManager);
		
		threadPool.start(httpclient,myProxyList);
		
		httpclient.getConnectionManager().shutdown();
		DataSourceUtil.closeDataSource();
	}

}
